package io.renren.modules.security.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.Result;
import io.renren.modules.security.dto.SelectKeywordDto;
import io.renren.modules.security.dto.UpdateKeywordDto;
import io.renren.modules.security.entity.Keyword;
import io.renren.modules.security.service.KeywordService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/keyword")
public class KeyWordController {

    @Resource
    private KeywordService keywordService;

    @GetMapping("/getWords")
    public Result<Page<Keyword>> getWords(SelectKeywordDto dto){
        Result<Page<Keyword>> result = new Result<>();
        result.setData(keywordService.getPage(dto));
        return result;
    }

    @PostMapping("/add")
    public Result<Boolean> add(@Validated @RequestBody UpdateKeywordDto dto){
        Result<Boolean> result = new Result<>();
        result.setData(keywordService.add(dto));
        return result;
    }

    @PostMapping("/update")
    public Result<Boolean> update(@Validated @RequestBody UpdateKeywordDto dto){
        Result<Boolean> result = new Result<>();
        result.setData(keywordService.update(dto));
        return result;
    }

    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable Long id){
        Result<Boolean> result = new Result<>();
        result.setData(keywordService.delete(id));
        return result;
    }
}
